#include "FileManager.h"

/**
  * PUBLIC METHODS
  */
QString FileManager::basePath()
{
    QString path;

    // LINUX
    #if defined(Q_OS_LINUX)
    path = QDir::homePath() + QDir::separator() + ".membermanager";

    // MAC
    #elif defined(Q_OS_MAC)
    QDir dir(QDir::currentPath());
    dir.cdUp();
    dir.cd("Resources");
    path = dir.absolutePath();

    // WINDOWS
    #else
    path = QDir::currentPath();
    #endif

    return path;
}

void FileManager::init()
{
    FileManager::_iconBasePath = FileManager::basePath() + QDir::separator() + "icons";
}

QIcon FileManager::icon(QString path) {
    QString fullPath = FileManager::_iconBasePath + QDir::separator() + path;
    QIcon icon;

    if (!FileManager::_iconCache.contains(fullPath)) {
        FileManager::_iconCache[fullPath] = QIcon(fullPath);
    }

    return FileManager::_iconCache[fullPath];
}

/**
  * PRIVATE STATIC VARIABLES
  */
QString FileManager::_iconBasePath = QString();
QMap<QString, QIcon> FileManager::_iconCache = QMap<QString, QIcon>();
